package reader_;


import org.junit.Test;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;

public class FileReader_ {
    public static void main(String s) {

    }
//单个字符读取
    @Test
    public void readerFile01() {
        //目的读取story文件
        //文件路径
        String filePath = "D:\\xuexi\\story.txt";
        FileReader fileReader = null;
        int data = 0;
        try {
            fileReader = new FileReader(filePath);
            //单个循环读取
            while ((data = fileReader.read()) != -1) {
                System.out.print((char) data);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    //字符数组读取
    @Test
    public void readerFile02() {
        System.out.println("readerFile02");
        //目的读取story文件
        //文件路径
        String filePath = "D:\\xuexi\\story.txt";
        FileReader fileReader = null;
        int datalen = 0;
        char[] datas=new char[4];
        try {
            fileReader = new FileReader(filePath);
            //read(datas)循环读取
            while ((datalen = fileReader.read(datas)) != -1) {
                System.out.print(new String(datas,0,datalen));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
